package cn.edu.zust.zql.controller;

import cn.edu.zust.zql.model.AccUser;
import cn.edu.zust.zql.service.AccUserService;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/12/21.
 */
@Controller
public class UserController {
    @Resource
    private AccUserService service;

    @RequestMapping("login")
    public String login(String username, String password, HttpSession session){
        AccUser accUser = service.validateUser(new AccUser(username, password));
        if(accUser!=null){
            session.setAttribute("user", accUser);
            return "jsp/index";
        }else{
            session.setAttribute("message", "密码错误");
            return "redirect:/";
        }
    }

    @RequestMapping("users")
    public ModelAndView users(ModelAndView mv){
        List<AccUser> allUser = service.getAllUser();
        mv.addObject("allUser", allUser);
        mv.setViewName("jsp/users");
        return mv;
    }

    @RequestMapping("user")
    public String toUserJsp(){
        return "jsp/user";
    }




}
